-
Notifications
You must be signed in to change notification settings - Fork 79
test: Link unit tests with nginx library. #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
ecb0d92 to
05a67cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for linking unit tests with nginx library by introducing a new "unittest" feature flag and building a static nginx library. The changes enable unit tests to use C functions from nginx by creating a special static library (libnginx) and adding necessary linker flags when the unittest feature is enabled.
- Introduces a new "unittest" feature flag for nginx-sys and nginx-src crates
- Creates a libnginx module with helper functions for nginx initialization in tests
- Adds build configuration to generate static nginx library and parse linker flags
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/core/pool.rs | Adds comprehensive unit tests for Pool functionality using nginx C functions |
| nginx-sys/build/main.rs | Extends makefile parsing to extract library flags and adds unittest feature support |
| nginx-sys/Cargo.toml | Defines unittest feature dependency on vendored nginx-src |
| nginx-src/src/lib.rs | Configures nginx build to include libnginx module when unittest feature is enabled |
| nginx-src/libnginx/ | New module providing C wrapper functions for nginx initialization in tests |
| Cargo.toml | Adds nginx-sys with unittest feature as dev dependency |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
05a67cb to
90fe91f
Compare
|
|
||
| use super::*; | ||
|
|
||
| #[link(name = "nginx", kind = "static")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be moved to nginx_sys::unittest::libngx_init, a module with test-related utilities conditional under #[cfg(feature = "unittest")].
Another thing to consider is that Rust unit-tests are executed in parallel, and test code will rely on a global state (ngx_cycle). Seems like this module should offer a mutex to guard the calls and the test use of nginx configuration. Adding prefix creation via tempfile to the wrapper might be a good idea as well. Although CARGO_TARGET_TMPDIR should be good enough for now.
If the tests are allowed to enable a feature flag on the current crate, I'd prefer to have this high-level wrapper in the ngx itself (because of std dependency).
Cargo.toml
Outdated
| maintenance = { status = "experimental" } | ||
|
|
||
| [dev-dependencies] | ||
| nginx-sys = { workspace = true, features = ["unittest"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be conditional under cfg(unix), until we can say that nginx-src works on Windows.
Some unit tests may use C functions from nginx. To support this scenario, special static library is built. Necessary linker flags are also added. Since these changes are needed for specific unit tests only, new feature "unittest" is defined. fixup
90fe91f to
1bf8253
Compare
Proposed changes
Some unit tests may use C functions from nginx. To support this scenario, special static library is built. Necessary linker flags are also added. Since these changes are needed for specific unit tests only, new feature "unittest" is defined in
nginx-sysandnginx-srccrates.Checklist
Before creating a PR, run through this checklist and mark each as complete.